<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>后台模板Springboot版本</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <link rel="stylesheet" href="/static/ztree/css/metroStyle/metroStyle.css">
        <script src="/static/js/jquery.min.js" charset="utf-8"></script>
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/static/js/ztree.js" charset="utf-8"></script>
        <script src="/static/js/excheck.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    <body>


        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" id="userId" name ="userId"  th:value="${user.userId}"/>
                    <div class="layui-form-item">
                        <label for="userCode" class="layui-form-label">
                            <span class="x-red">*</span> 用户名
                        </label>
                        <div class="layui-input-inline" >
                          <input type="text" id="userCode" name="userCode" required="" lay-verify="required" th:value="${user.userCode}"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="realName" class="layui-form-label">
                            <span class="x-red">*</span>真实姓名
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="realName" name="realName" required="" lay-verify="required" th:value="${user.realName}"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="phone" class="layui-form-label">
                            <span class="x-red">*</span>手机号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" required="" lay-verify="required|phone" th:value="${user.phone}"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="email" class="layui-form-label">
                            <span class="x-red">*</span>邮箱
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="email" name="email" required="" lay-verify="required|email" th:value="${user.email}"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            选择角色
                        </label>

                            <div class="layui-input-block">
                                <!-- radio 单选框选中
                                      th:attr ="checked=${role.id == 10001?true:false}"
                                     checkbox 复选框 选中回显
                                      th:attr ="checked=${roleList.contains(role.id)?true:false}"
                                 -->
                                <input th:each="role:${roleList}" name="roleId" lay-skin="primary" type="radio"
                                       th:value="${role.id}"
                                       th:attr ="checked=${role.id == user.roleId ? true:false}"
                                       th:title="${role.roleName}" >
                            </div>

                    </div>

                    <div class="layui-form-item">
                        <button  class="layui-btn" lay-filter="add" lay-submit="" style="margin-left: 111px;">
                            添加
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <script>
            layui.use(['form', 'layer'],
               function() {
                    $ = layui.jquery;
                    var form = layui.form,
                    layer = layui.layer;
                    //监听提交
                    form.on('submit(add)',function(data){
                        $.ajax({
                            url:"/system/user",
                            type:"put",
                            dateType:'json',
                            data:{
                                "userId" : data.field.userId,
                                "userCode" : data.field.userCode,
                                "realName" : data.field.realName,
                                "phone": data.field.phone,
                                "email": data.field.email,
                                "roleId":$("input[name='roleId']:checked").val()
                            },
                            success:function(result){
                                if(result.code == 0){
                                    layer.alert("修改成功",{icon:6},function(){
                                        //关闭当前frame
                                        xadmin.close();
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });

                                }

                            }
                        });
                        return false;
                    });




            });
        </script>

    </body>

</html>
